import { apiInit } from '@/services'
import { message } from 'ant-design-vue'
import { i18n } from '@/locales'

export default function useListDescription() {
	const { $t } = i18n
	const api = apiInit()
	const colorList: string[] = ['#FFA665', '#5682FF', '#EB5A6B']
	const saveRecent = async (id: string) => {
		const res = await api.default.SaveRecentPrivateV2POST({
			payload: { resource_id: id },
		})
		return res.data
	}
	const saveFavorite = async (id: string, type = '0') => {
		const res = await api.default.SaveCollectUserPrivateV2POST({
			payload: {
				op_type: type,
				resource_id: id,
			},
		})
		if (res.code === '000000') {
			message.success($t('pages.home.removed', '移除成功'))
			return true
		} else {
			message.error(res.message || $t('pages.home.removedFailed', '移除失败'))
			return false
		}
	}
	return {
		saveRecent,
		colorList,
		saveFavorite,
	}
}
